﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common;
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Modules;
    using DotNetNuke.Services.Exceptions;
    using DotNetNuke.Services.Localization;
    using DotNetNuke.UI.UserControls;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Xml;

    public class AdminSettings : BaseAdminModule
    {
        [AccessedThroughProperty("cmdAdd")]
        private LinkButton _cmdAdd;
        [AccessedThroughProperty("cmdCancel")]
        private LinkButton _cmdCancel;
        [AccessedThroughProperty("cmdDelete")]
        private LinkButton _cmdDelete;
        [AccessedThroughProperty("cmdUpdate")]
        private LinkButton _cmdUpdate;
        [AccessedThroughProperty("chkHostOnly")]
        private CheckBox _chkHostOnly;
        [AccessedThroughProperty("chkTextBoxEdit")]
        private CheckBox _chkTextBoxEdit;
        [AccessedThroughProperty("chkUseFileSystem")]
        private CheckBox _chkUseFileSystem;
        [AccessedThroughProperty("ddlGroups")]
        private DropDownList _ddlGroups;
        [AccessedThroughProperty("ddlTabs")]
        private DropDownList _ddlTabs;
        [AccessedThroughProperty("dlListMenu")]
        private DataList _dlListMenu;
        [AccessedThroughProperty("labelGroupName")]
        private UserControl _labelGroupName;
        [AccessedThroughProperty("labelMessage")]
        private UserControl _labelMessage;
        [AccessedThroughProperty("labelTemplName")]
        private UserControl _labelTemplName;
        [AccessedThroughProperty("pnlEdit")]
        private Panel _pnlEdit;
        [AccessedThroughProperty("phTreeMenu")]
        private PlaceHolder _phTreeMenu;
        [AccessedThroughProperty("rblCtrlType")]
        private RadioButtonList _rblCtrlType;
        [AccessedThroughProperty("rblSettingValue")]
        private RadioButtonList _rblSettingValue;
        [AccessedThroughProperty("selectlang")]
        private SelectLang _selectlang;
        [AccessedThroughProperty("txtEditor")]
        private UserControl _txtEditor;
        [AccessedThroughProperty("txtHelp")]
        private TextBox _txtHelp;
        [AccessedThroughProperty("txtMessage")]
        private TextBox _txtMessage;
        [AccessedThroughProperty("txtTemplName")]
        private TextBox _txtTemplName;
        [AccessedThroughProperty("valReqCategoryName")]
        private RequiredFieldValidator _valReqCategoryName;
        protected bool EditTemplateMode;
        protected string TemID;

        public AdminSettings()
        {
            base.Load += new EventHandler(this.Page_Load);
            this.TemID = "";
            this.EditTemplateMode = false;
        }

        private string BuildAdminSettingLink(ref ArrayList aryList, string GroupName, Hashtable hFlagList)
        {
            NB_Store_SettingsTextInfo current;
            IEnumerator enumerator=null;
            IEnumerator enumerator2=null;
            ArrayList list = new ArrayList();
            string str2 = "<ul>";
            try
            {
                enumerator = aryList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (NB_Store_SettingsTextInfo) enumerator.Current;
                    if (current.GroupRef == null)
                    {
                        current.GroupRef = "";
                    }
                    if ((current.GroupRef == GroupName) | (GroupName == ""))
                    {
                        str2 = str2 + "<li>";
                        str2 = str2 + this.getSettingLink(current, hFlagList);
                        list.Add(current);
                        str2 = str2 + "</li>";
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            str2 = str2 + "</ul>";
            try
            {
                enumerator2 = list.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    current = (NB_Store_SettingsTextInfo) enumerator2.Current;
                    aryList.Remove(current);
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
            return str2;
        }

        private Hashtable BuildFlags(string CacheName, ArrayList aryList, string SettingName = "")
        {
            ArrayList list;
            Hashtable objObject = new Hashtable();
            SettingsController controller = new SettingsController();
            string str = "";
            if ((SettingName != "") & (SharedFunctions.getLangCache(this.PortalId, CacheName, SharedFunctions.GetCurrentCulture()) != null))
            {
                IEnumerator enumerator=null;
                objObject = (Hashtable) SharedFunctions.getLangCache(this.PortalId, CacheName, SharedFunctions.GetCurrentCulture());
                if (objObject.ContainsKey(SettingName))
                {
                    objObject.Remove(SettingName);
                }
                if (this.EditTemplateMode)
                {
                    list = controller.GetSettingsTexts(this.PortalId, "", true, SettingName);
                }
                else
                {
                    list = controller.GetSettingListObj(this.PortalId, "", true, SettingName);
                }
                str = "&nbsp;";
                try
                {
                    enumerator = list.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        NB_Store_SettingsTextInfo current = (NB_Store_SettingsTextInfo) enumerator.Current;
                        if (current.Lang.Trim() != "None")
                        {
                            str = str + "<img src=\"" + DotNetNuke.Common.Globals.ResolveUrl("~/images/flags/" + current.Lang.Trim() + ".gif") + "\" height=\"10\" width=\"15\" border=\"0\" />";
                        }
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                objObject.Add(SettingName, str);
                return objObject;
            }
            if (SharedFunctions.getLangCache(this.PortalId, CacheName, SharedFunctions.GetCurrentCulture()) == null)
            {
                IEnumerator enumerator2=null;
                try
                {
                    enumerator2 = aryList.GetEnumerator();
                    while (enumerator2.MoveNext())
                    {
                        IEnumerator enumerator3=null;
                        NB_Store_SettingsTextInfo info2 = (NB_Store_SettingsTextInfo) enumerator2.Current;
                        if (this.EditTemplateMode)
                        {
                            list = controller.GetSettingsTexts(this.PortalId, "", true, info2.SettingName);
                        }
                        else
                        {
                            list = controller.GetSettingListObj(this.PortalId, "", true, info2.SettingName);
                        }
                        str = "&nbsp;";
                        try
                        {
                            enumerator3 = list.GetEnumerator();
                            while (enumerator3.MoveNext())
                            {
                                NB_Store_SettingsTextInfo info3 = (NB_Store_SettingsTextInfo) enumerator3.Current;
                                if (info3.Lang.Trim() != "None")
                                {
                                    str = str + "<img src=\"" + DotNetNuke.Common.Globals.ResolveUrl("~/images/flags/" + info3.Lang.Trim() + ".gif") + "\" height=\"10\" width=\"15\" border=\"0\" />";
                                }
                            }
                        }
                        finally
                        {
                            if (enumerator3 is IDisposable)
                            {
                                (enumerator3 as IDisposable).Dispose();
                            }
                        }
                        objObject.Add(info2.SettingName, str);
                    }
                }
                finally
                {
                    if (enumerator2 is IDisposable)
                    {
                        (enumerator2 as IDisposable).Dispose();
                    }
                }
                SharedFunctions.setLangCache(this.PortalId, CacheName, SharedFunctions.GetCurrentCulture(), objObject);
                return objObject;
            }
            return (Hashtable) SharedFunctions.getLangCache(this.PortalId, CacheName, SharedFunctions.GetCurrentCulture());
        }

        private void BuildGroupList(ref DropDownList ddlGroups, XmlDataDocument xmlDoc, string xPath, string LevelIndent)
        {
            IEnumerator enumerator=null;
            XmlNodeList childNodes = xmlDoc.SelectSingleNode(xPath).ChildNodes;
            try
            {
                enumerator = childNodes.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    XmlNode current = (XmlNode) enumerator.Current;
                    ListItem item = new ListItem {
                        Text = LevelIndent + current.Attributes["text"].InnerText,
                        Value = xPath + "/" + current.Name
                    };
                    ddlGroups.Items.Add(item);
                    this.BuildGroupList(ref ddlGroups, xmlDoc, xPath + "/" + current.Name, LevelIndent + ".");
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        private string BuildTreeMenu(XmlDataDocument xmlDoc, ref ArrayList aryList, string xPath, Hashtable hFlagList)
        {
            IEnumerator enumerator=null;
            string str4 = "";
            string str3 = "</ul>";
            string str2 = "";
            if (xPath == "root")
            {
                str4 = str4 + "<ul id=\"AdminTreeMenu\" class=\"NBright_TreeView\">";
            }
            else
            {
                str4 = str4 + "<ul>";
            }
            XmlNodeList childNodes = xmlDoc.SelectSingleNode(xPath).ChildNodes;
            try
            {
                enumerator = childNodes.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    XmlNode current = (XmlNode) enumerator.Current;
                    str2 = str2 + "<li>";
                    str2 = str2 + "<font class=\"NBright_AdminTree\">" + current.Attributes["text"].InnerText + "</font>";
                    str2 = str2 + this.BuildAdminSettingLink(ref aryList, xPath + "/" + current.Name, hFlagList);
                    str2 = str2 + this.BuildTreeMenu(xmlDoc, ref aryList, xPath + "/" + current.Name, hFlagList);
                    str2 = str2 + "</li>";
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            if ((xPath == "root") && (aryList.Count > 0))
            {
                str2 = (str2 + "<li>" + "<font class=\"NBright_AdminTree\">Unknown</font>") + this.BuildAdminSettingLink(ref aryList, "", hFlagList) + "</li>";
            }
            if (str2 != "")
            {
                str2 = str4 + str2 + str3;
            }
            return str2;
        }

        private void cmdAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.EditTemplateMode)
                {
                    this.Response.Redirect(this.EditUrl("TemId", "0", "AdminSetting", new string[] { "etmode=1" }), true);
                }
                else
                {
                    this.Response.Redirect(this.EditUrl("TemId", "0", "AdminSetting", new string[] { "etmode=0" }), true);
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.EditTemplateMode)
                {
                    this.Response.Redirect(this.EditUrl("etmode", "1", "AdminSetting"), true);
                }
                else
                {
                    this.Response.Redirect(this.EditUrl("etmode", "0", "AdminSetting"), true);
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void cmdDelete_Click(object sender, EventArgs e)
        {
            try
            {
                NB_Store_SettingsTextInfo info;
                SettingsController controller = new SettingsController();
                if (this.EditTemplateMode)
                {
                    info = controller.GetSettingsTextNotCached(this.PortalId, this.TemID, this.selectlang.SelectedLang);
                    controller.DeleteSettingsText(this.PortalId, this.TemID, this.selectlang.SelectedLang);
                }
                else
                {
                    info = controller.GetSettingObjNotCached(this.PortalId, this.TemID, this.selectlang.SelectedLang);
                    controller.DeleteSetting(this.PortalId, this.TemID, this.selectlang.SelectedLang);
                }
                SharedFunctions.removeLangCache(this.PortalId, "nbstoreadminsettingtreemenu" + this.UserId.ToString());
                SharedFunctions.removeLangCache(this.PortalId, "nbstoreadmintemplatetreemenu" + this.UserId.ToString());
                if (info != null)
                {
                    SharedFunctions.UpdateLog(this.UserId, this.ControlName + " - " + MethodBase.GetCurrentMethod().Name + " - " + XmlUtils.Serialize(info));
                    if (info.Lang.Trim() == "None")
                    {
                        if (this.EditTemplateMode)
                        {
                            this.Response.Redirect(this.EditUrl("etmode", "1", "AdminSetting"), true);
                        }
                        else
                        {
                            this.Response.Redirect(this.EditUrl("etmode", "0", "AdminSetting"), true);
                        }
                    }
                }
                if (this.EditTemplateMode)
                {
                    this.Response.Redirect(this.EditUrl("TemId", info.SettingName.ToString(), "AdminSetting", new string[] { "etmode=1" }), true);
                }
                else
                {
                    this.Response.Redirect(this.EditUrl("TemId", info.SettingName.ToString(), "AdminSetting", new string[] { "etmode=0" }), true);
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                NB_Store_SettingsTextInfo info = this.updateSettings();
                if (info != null)
                {
                    this.selectlang.EditedLang = this.selectlang.SelectedLang;
                    if (this.EditTemplateMode)
                    {
                        this.Response.Redirect(this.EditUrl("TemId", info.SettingName.ToString(), "AdminSetting", new string[] { "etmode=1" }), true);
                    }
                    else
                    {
                        this.Response.Redirect(this.EditUrl("TemId", info.SettingName.ToString(), "AdminSetting", new string[] { "etmode=0" }), true);
                    }
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void chkTextBoxEdit_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                SharedFunctions.SetStoreSetting(this.PortalId, "textboxedit.flag", this.chkTextBoxEdit.Checked.ToString(), "None", false);
                if (this.EditTemplateMode)
                {
                    this.Response.Redirect(this.EditUrl("TemID", this.TemID, "AdminSetting", new string[] { "etmode=1" }), true);
                }
                else
                {
                    this.Response.Redirect(this.EditUrl("TemID", this.TemID, "AdminSetting", new string[] { "etmode=0" }), true);
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void chkUseFileSystem_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                SharedFunctions.SetStoreSetting(this.PortalId, "filesystemtemplates.flag", this.chkUseFileSystem.Checked.ToString(), "None", false);
                if (this.chkUseFileSystem.Checked && (this.updateSettings() != null))
                {
                    this.selectlang.EditedLang = this.selectlang.SelectedLang;
                }
                if (this.EditTemplateMode)
                {
                    this.Response.Redirect(this.EditUrl("TemID", this.TemID, "AdminSetting", new string[] { "etmode=1" }), true);
                }
                else
                {
                    this.Response.Redirect(this.EditUrl("TemID", this.TemID, "AdminSetting", new string[] { "etmode=0" }), true);
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private string getSettingLink(NB_Store_SettingsTextInfo itemInfo, Hashtable hFlagList)
        {
            string str2 = "";
            string left = "";
            if (this.EditTemplateMode)
            {
                str2 = this.EditUrl("TemID", itemInfo.SettingName, "AdminSetting", new string[] { "etmode=1" });
            }
            else
            {
                str2 = this.EditUrl("TemID", itemInfo.SettingName, "AdminSetting", new string[] { "etmode=0" });
            }
            left = Conversions.ToString(Operators.ConcatenateObject(left, Operators.ConcatenateObject(("<a class=\"NBright_AdminTreeSetting\" href=\"" + str2 + "\" >") + itemInfo.SettingName + "</a>", hFlagList[itemInfo.SettingName])));
            if (itemInfo.HostOnly)
            {
                return (left + "<img src=\"" + this.ResolveUrl("img/bullet_key.png") + "\" border=\"0\" />");
            }
            return (left + "<img src=\"" + this.ResolveUrl("img/bullet_wrench.png") + "\" border=\"0\" />");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.selectlang.DisplayNoLang = true;
                if (this.Request.QueryString["TemId"] != null)
                {
                    this.TemID = this.Request.QueryString["TemId"];
                }
                else
                {
                    this.TemID = "";
                }
                if (this.Request.QueryString["etmode"] != null)
                {
                    if (this.Request.QueryString["etmode"] == "1")
                    {
                        this.EditTemplateMode = true;
                    }
                    else
                    {
                        this.EditTemplateMode = false;
                    }
                }
                else
                {
                    this.EditTemplateMode = false;
                }
                if (!this.Page.IsPostBack)
                {
                    if (this.selectlang.EditedLang == "")
                    {
                        this.selectlang.SelectedLang = "None";
                    }
                    this.selectlang.EditedLang = "";
                    this.cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" + DotNetNuke.Services.Localization.Localization.GetString("DeleteItem", this.LocalResourceFile) + "');");
                    if (this.TemID == "")
                    {
                        this.pnlEdit.Visible = false;
                    }
                    else
                    {
                        this.populateEdit();
                    }
                    this.ShowTreeMenu();
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void populateEdit()
        {
            NB_Store_SettingsTextInfo info;
            SettingsController controller = new SettingsController();
            this.pnlEdit.Visible = true;
            this.selectlang.DisplayNoLang = true;
            if (this.Page.IsPostBack)
            {
                this.selectlang.Refresh();
            }
            this.txtMessage.Visible = false;
            this.rblSettingValue.Visible = false;
            this.txtEditor.Visible = false;
            this.chkTextBoxEdit.Visible = false;
            this.chkUseFileSystem.Visible = false;
            this.ddlTabs.Visible = false;
            if (this.EditTemplateMode)
            {
                this.rblCtrlType.Visible = false;
            }
            DropDownList ddlGroups = this.ddlGroups;
            this.PopulateGroupDropdownlist(ref ddlGroups);
            this.ddlGroups = ddlGroups;
            if (this.EditTemplateMode)
            {
                info = controller.GetSettingsTextNotCached(this.PortalId, this.TemID, this.selectlang.SelectedLang);
            }
            else
            {
                info = controller.GetSettingObjNotCached(this.PortalId, this.TemID, this.selectlang.SelectedLang);
            }
            if (info == null)
            {
                return;
            }
            if (info.GroupRef == null)
            {
                info.GroupRef = "";
            }
            if (this.ddlGroups.Items.FindByValue(info.GroupRef) != null)
            {
                this.ddlGroups.ClearSelection();
                this.ddlGroups.Items.FindByValue(info.GroupRef).Selected = true;
            }
            this.txtHelp.Enabled = false;
            if (this.EditTemplateMode)
            {
                bool flag = SharedFunctions.GetStoreSettingBoolean(this.PortalId, "textboxedit.flag", "None");
                this.chkTextBoxEdit.Visible = true;
                this.chkTextBoxEdit.Checked = flag;
                this.chkUseFileSystem.Visible = true;
                if (SharedFunctions.GetStoreSettingBoolean(this.PortalId, "debug.mode", "None"))
                {
                    this.chkUseFileSystem.Enabled = true;
                    this.chkUseFileSystem.Checked = SharedFunctions.GetStoreSettingBoolean(this.PortalId, "filesystemtemplates.flag", "None");
                }
                else
                {
                    this.chkUseFileSystem.Enabled = false;
                    this.chkUseFileSystem.Checked = false;
                }
                if (flag | (SharedFunctions.GetStoreSettingBoolean(this.PortalId, "filesystemtemplates.flag", "None") & SharedFunctions.GetStoreSettingBoolean(this.PortalId, "debug.mode", "None")))
                {
                    this.txtEditor.Visible = false;
                    this.txtMessage.Visible = true;
                    this.txtMessage.TextMode = TextBoxMode.MultiLine;
                    this.txtMessage.Height = 400;
                    this.txtMessage.Wrap = false;
                    this.txtMessage.Text = HttpUtility.HtmlDecode(info.SettingText);
                }
                else
                {
                    this.txtEditor.Visible = true;
                    this.txtMessage.Visible = false;
                    ((TextEditor) this.txtEditor).Text = info.SettingText;
                }
                if (SharedFunctions.GetStoreSettingBoolean(this.PortalId, "filesystemtemplates.flag", "None") & SharedFunctions.GetStoreSettingBoolean(this.PortalId, "debug.mode", "None"))
                {
                    this.txtEditor.Visible = false;
                    this.txtMessage.Enabled = false;
                }
            }
            else if (info.CtrlType == "")
            {
                this.rblCtrlType.Visible = true;
                this.txtMessage.Visible = true;
                this.txtMessage.Visible = true;
                this.txtMessage.MaxLength = 0x7d0;
                this.txtMessage.TextMode = TextBoxMode.MultiLine;
                this.txtMessage.Height = 400;
                this.txtMessage.Wrap = false;
                this.txtMessage.Text = info.SettingValue;
            }
            else
            {
                this.rblCtrlType.Visible = false;
                switch (info.CtrlType.ToLower())
                {
                    case "textbox":
                        this.txtMessage.Visible = true;
                        this.txtMessage.MaxLength = 0x7d0;
                        this.txtMessage.TextMode = TextBoxMode.SingleLine;
                        this.txtMessage.Text = info.SettingValue;
                        goto Label_05B7;

                    case "boolean":
                        this.rblSettingValue.Visible = true;
                        if (this.rblSettingValue.Items.Count < 2)
                        {
                            ListItem item = new ListItem {
                                Value = "1",
                                Text = DotNetNuke.Services.Localization.Localization.GetString("True", this.LocalResourceFile)
                            };
                            this.rblSettingValue.Items.Add(item);
                            item = new ListItem {
                                Value = "0",
                                Text = DotNetNuke.Services.Localization.Localization.GetString("False", this.LocalResourceFile)
                            };
                            this.rblSettingValue.Items.Add(item);
                        }
                        try
                        {
                            if (Conversions.ToBoolean(info.SettingValue))
                            {
                                this.rblSettingValue.SelectedValue = "1";
                            }
                            else
                            {
                                this.rblSettingValue.SelectedValue = "0";
                            }
                        }
                        catch (Exception exception1)
                        {
                            ProjectData.SetProjectError(exception1);
                            Exception exception = exception1;
                            this.rblSettingValue.SelectedValue = "0";
                            ProjectData.ClearProjectError();
                        }
                        goto Label_05B7;

                    case "websitetab":
                        SharedFunctions.populateTabsList(this.ddlTabs, this.PortalSettings, "");
                        if (this.ddlTabs.Items.FindByValue(info.SettingValue) != null)
                        {
                            this.ddlTabs.ClearSelection();
                            this.ddlTabs.Items.FindByValue(info.SettingValue).Selected = true;
                        }
                        this.ddlTabs.Visible = true;
                        goto Label_05B7;
                }
                this.txtMessage.Visible = true;
                this.txtMessage.MaxLength = 0x7d0;
                this.txtMessage.TextMode = TextBoxMode.MultiLine;
                this.txtMessage.Height = 400;
                this.txtMessage.Wrap = false;
                this.txtMessage.Text = info.SettingValue;
            }
        Label_05B7:
            this.txtTemplName.Text = info.SettingName;
            this.chkHostOnly.Checked = info.HostOnly;
            this.txtHelp.Text = DotNetNuke.Services.Localization.Localization.GetString(info.SettingName, this.LocalResourceFile);
            if (this.UserInfo.IsSuperUser | this.UserInfo.IsInRole("Administrator"))
            {
                this.cmdAdd.Visible = true;
            }
            else
            {
                this.cmdAdd.Visible = false;
            }
            if (this.UserInfo.IsSuperUser | this.UserInfo.IsInRole("Administrators"))
            {
                this.chkHostOnly.Enabled = true;
            }
            else
            {
                this.chkHostOnly.Enabled = false;
                if (info.HostOnly)
                {
                    this.txtMessage.Enabled = false;
                    this.txtTemplName.Enabled = false;
                    this.cmdDelete.Visible = false;
                    this.cmdUpdate.Visible = false;
                }
            }
        }

        private void PopulateGroupDropdownlist(ref DropDownList ddlGroups)
        {
            string xml = "";
            XmlDataDocument xmlDoc = new XmlDataDocument();
            if (this.EditTemplateMode)
            {
                xml = SharedFunctions.GetStoreSetting(this.PortalId, "admintemplates.groups", SharedFunctions.GetCurrentCulture());
            }
            else
            {
                xml = SharedFunctions.GetStoreSetting(this.PortalId, "adminsettings.groups", SharedFunctions.GetCurrentCulture());
            }
            try
            {
                xmlDoc.LoadXml(xml);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                ddlGroups.Items.Add("ERROR - Invalid xml setting");
                ProjectData.ClearProjectError();
                return;
            }
            this.BuildGroupList(ref ddlGroups, xmlDoc, "root", "");
        }

        private void selectlang_AfterChange(object source, DataListCommandEventArgs e, string PreviousEditLang)
        {
            if (e.CommandName == "Change")
            {
                this.ShowTreeMenu();
                this.populateEdit();
            }
        }

        private void selectlang_BeforeChange(object source, DataListCommandEventArgs e, string NewEditLang)
        {
            if (e.CommandName == "Change")
            {
            }
        }

        private void ShowTreeMenu()
        {
            if (this.EditTemplateMode)
            {
                this.ShowTreeMenu("nbstoreadmintemplatetreemenu" + this.UserId.ToString());
            }
            else
            {
                this.ShowTreeMenu("nbstoreadminsettingtreemenu" + this.UserId.ToString());
            }
        }

        private void ShowTreeMenu(string CacheName)
        {
            SettingsController controller = new SettingsController();
            string objObject = "";
            bool flag = SharedFunctions.GetStoreSettingBoolean(this.PortalId, "debug.mode", "None");
            Collection collection = new Collection();
            if ((SharedFunctions.getLangCache(this.PortalId, CacheName, SharedFunctions.GetCurrentCulture()) == null) | flag)
            {
                ArrayList list;
                Hashtable hashtable;
                IEnumerator enumerator=null;
                string xml = "";
                XmlDataDocument xmlDoc = new XmlDataDocument();
                bool flag2 = false;
                if (this.EditTemplateMode)
                {
                    xml = SharedFunctions.GetStoreSetting(this.PortalId, "admintemplates.groups", SharedFunctions.GetCurrentCulture());
                }
                else
                {
                    xml = SharedFunctions.GetStoreSetting(this.PortalId, "adminsettings.groups", SharedFunctions.GetCurrentCulture());
                }
                try
                {
                    xmlDoc.LoadXml(xml);
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    Exception exception = exception1;
                    this.phTreeMenu.Controls.Add(new LiteralControl("Invalid xml setting - \"adminsettings.groups\" "));
                    flag2 = true;
                    ProjectData.ClearProjectError();
                }
                if (this.EditTemplateMode)
                {
                    list = controller.GetSettingsTexts(this.PortalId, "None", this.UserInfo.IsSuperUser | this.UserInfo.IsInRole("Administrators"), "");
                    hashtable = this.BuildFlags("nbstoreadmintemplateflaglist" + this.UserId.ToString(), list, this.TemID);
                }
                else
                {
                    list = controller.GetSettingListObj(this.PortalId, "None", this.UserInfo.IsSuperUser | this.UserInfo.IsInRole("Administrators"), "");
                    hashtable = this.BuildFlags("nbstoreadminsettingflaglist" + this.UserId.ToString(), list, this.TemID);
                }
                try
                {
                    enumerator = list.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        NB_Store_SettingsTextInfo current = (NB_Store_SettingsTextInfo) enumerator.Current;
                        collection.Add("<div class=\"NBright_SettingMenuListItem\">" + this.getSettingLink(current, hashtable) + "</div>", null, null, null);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                if (!flag2)
                {
                    objObject = this.BuildTreeMenu(xmlDoc, ref list, "root", hashtable);
                }
                SharedFunctions.setLangCache(this.PortalId, CacheName, SharedFunctions.GetCurrentCulture(), objObject);
                if (this.EditTemplateMode)
                {
                    SharedFunctions.setLangCache(this.PortalId, "nbstoreadmintemplatelistmenu" + this.UserId.ToString(), SharedFunctions.GetCurrentCulture(), collection);
                }
                else
                {
                    SharedFunctions.setLangCache(this.PortalId, "nbstoreadminsettinglistmenu" + this.UserId.ToString(), SharedFunctions.GetCurrentCulture(), collection);
                }
            }
            else
            {
                objObject = SharedFunctions.getLangCache(this.PortalId, CacheName, SharedFunctions.GetCurrentCulture()).ToString();
                if (this.EditTemplateMode)
                {
                    if (SharedFunctions.getLangCache(this.PortalId, "nbstoreadmintemplatelistmenu" + this.UserId.ToString(), SharedFunctions.GetCurrentCulture()) != null)
                    {
                        collection = (Collection) SharedFunctions.getLangCache(this.PortalId, "nbstoreadmintemplatelistmenu" + this.UserId.ToString(), SharedFunctions.GetCurrentCulture());
                    }
                }
                else if (SharedFunctions.getLangCache(this.PortalId, "nbstoreadminsettinglistmenu" + this.UserId.ToString(), SharedFunctions.GetCurrentCulture()) != null)
                {
                    collection = (Collection) SharedFunctions.getLangCache(this.PortalId, "nbstoreadminsettinglistmenu" + this.UserId.ToString(), SharedFunctions.GetCurrentCulture());
                }
            }
            this.phTreeMenu.Controls.Add(new LiteralControl(objObject));
            if (this.pnlEdit.Visible)
            {
                this.dlListMenu.Visible = false;
            }
            else
            {
                this.dlListMenu.DataSource = collection;
                this.dlListMenu.DataBind();
            }
        }

        private NB_Store_SettingsTextInfo updateSettings()
        {
            SettingsController controller = new SettingsController();
            NB_Store_SettingsTextInfo objInfo = new NB_Store_SettingsTextInfo();
            if (this.EditTemplateMode)
            {
                objInfo = controller.GetSettingsTextNotCached(this.PortalId, this.TemID, this.selectlang.SelectedLang);
            }
            else
            {
                objInfo = controller.GetSettingObjNotCached(this.PortalId, this.TemID, this.selectlang.SelectedLang);
            }
            if (objInfo == null)
            {
                objInfo = new NB_Store_SettingsTextInfo();
            }
            objInfo.Lang = this.selectlang.SelectedLang;
            objInfo.PortalID = this.PortalId;
            objInfo.SettingName = this.txtTemplName.Text;
            if (this.EditTemplateMode)
            {
                if (this.txtMessage.Visible)
                {
                    objInfo.SettingText = HttpUtility.HtmlEncode(this.txtMessage.Text);
                }
                else
                {
                    objInfo.SettingText = ((TextEditor) this.txtEditor).Text;
                }
            }
            else
            {
                if (this.txtMessage.Visible)
                {
                    objInfo.SettingValue = this.txtMessage.Text;
                }
                if (this.rblSettingValue.Visible)
                {
                    objInfo.SettingValue = this.rblSettingValue.SelectedValue;
                }
                if (this.ddlTabs.Visible)
                {
                    objInfo.SettingValue = this.ddlTabs.SelectedValue;
                }
            }
            objInfo.GroupRef = this.ddlGroups.SelectedValue;
            if (this.rblCtrlType.Visible)
            {
                objInfo.CtrlType = this.rblCtrlType.SelectedValue;
            }
            objInfo.HostOnly = this.chkHostOnly.Checked;
            if (this.EditTemplateMode)
            {
                controller.UpdateObjSettingsText(objInfo);
            }
            else
            {
                controller.UpdateObjSettingObj(objInfo);
            }
            if (objInfo != null)
            {
                SharedFunctions.UpdateLog(this.UserId, this.ControlName + " - " + MethodBase.GetCurrentMethod().Name + " - " + XmlUtils.Serialize(objInfo));
            }
            SharedFunctions.removeStoreTemplateCache(this.PortalId);
            SharedFunctions.removeLangCache(this.PortalId, "nbstoreadminsettingtreemenu" + this.UserId.ToString());
            SharedFunctions.removeLangCache(this.PortalId, "nbstoreadmintemplatetreemenu" + this.UserId.ToString());
            return objInfo;
        }

        protected virtual LinkButton cmdAdd
        {
            get
            {
                return this._cmdAdd;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdAdd_Click);
                if (this._cmdAdd != null)
                {
                    this._cmdAdd.Click -= handler;
                }
                this._cmdAdd = value;
                if (this._cmdAdd != null)
                {
                    this._cmdAdd.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdCancel
        {
            get
            {
                return this._cmdCancel;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdCancel_Click);
                if (this._cmdCancel != null)
                {
                    this._cmdCancel.Click -= handler;
                }
                this._cmdCancel = value;
                if (this._cmdCancel != null)
                {
                    this._cmdCancel.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdDelete
        {
            get
            {
                return this._cmdDelete;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdDelete_Click);
                if (this._cmdDelete != null)
                {
                    this._cmdDelete.Click -= handler;
                }
                this._cmdDelete = value;
                if (this._cmdDelete != null)
                {
                    this._cmdDelete.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdUpdate
        {
            get
            {
                return this._cmdUpdate;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdUpdate_Click);
                if (this._cmdUpdate != null)
                {
                    this._cmdUpdate.Click -= handler;
                }
                this._cmdUpdate = value;
                if (this._cmdUpdate != null)
                {
                    this._cmdUpdate.Click += handler;
                }
            }
        }

        protected virtual CheckBox chkHostOnly
        {
            get
            {
                return this._chkHostOnly;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._chkHostOnly = value;
            }
        }

        protected virtual CheckBox chkTextBoxEdit
        {
            get
            {
                return this._chkTextBoxEdit;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.chkTextBoxEdit_CheckedChanged);
                if (this._chkTextBoxEdit != null)
                {
                    this._chkTextBoxEdit.CheckedChanged -= handler;
                }
                this._chkTextBoxEdit = value;
                if (this._chkTextBoxEdit != null)
                {
                    this._chkTextBoxEdit.CheckedChanged += handler;
                }
            }
        }

        protected virtual CheckBox chkUseFileSystem
        {
            get
            {
                return this._chkUseFileSystem;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.chkUseFileSystem_CheckedChanged);
                if (this._chkUseFileSystem != null)
                {
                    this._chkUseFileSystem.CheckedChanged -= handler;
                }
                this._chkUseFileSystem = value;
                if (this._chkUseFileSystem != null)
                {
                    this._chkUseFileSystem.CheckedChanged += handler;
                }
            }
        }

        protected virtual DropDownList ddlGroups
        {
            get
            {
                return this._ddlGroups;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._ddlGroups = value;
            }
        }

        protected virtual DropDownList ddlTabs
        {
            get
            {
                return this._ddlTabs;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._ddlTabs = value;
            }
        }

        protected virtual DataList dlListMenu
        {
            get
            {
                return this._dlListMenu;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._dlListMenu = value;
            }
        }

        protected virtual UserControl labelGroupName
        {
            get
            {
                return this._labelGroupName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelGroupName = value;
            }
        }

        protected virtual UserControl labelMessage
        {
            get
            {
                return this._labelMessage;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelMessage = value;
            }
        }

        protected virtual UserControl labelTemplName
        {
            get
            {
                return this._labelTemplName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._labelTemplName = value;
            }
        }

        protected virtual Panel pnlEdit
        {
            get
            {
                return this._pnlEdit;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._pnlEdit = value;
            }
        }

        protected virtual PlaceHolder phTreeMenu
        {
            get
            {
                return this._phTreeMenu;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._phTreeMenu = value;
            }
        }

        protected virtual RadioButtonList rblCtrlType
        {
            get
            {
                return this._rblCtrlType;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._rblCtrlType = value;
            }
        }

        protected virtual RadioButtonList rblSettingValue
        {
            get
            {
                return this._rblSettingValue;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._rblSettingValue = value;
            }
        }

        protected virtual SelectLang selectlang
        {
            get
            {
                return this._selectlang;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                SelectLang.AfterChangeEventHandler handler = new SelectLang.AfterChangeEventHandler(this.selectlang_AfterChange);
                SelectLang.BeforeChangeEventHandler handler2 = new SelectLang.BeforeChangeEventHandler(this.selectlang_BeforeChange);
                if (this._selectlang != null)
                {
                    this._selectlang.AfterChange -= handler;
                    this._selectlang.BeforeChange -= handler2;
                }
                this._selectlang = value;
                if (this._selectlang != null)
                {
                    this._selectlang.AfterChange += handler;
                    this._selectlang.BeforeChange += handler2;
                }
            }
        }

        protected virtual UserControl txtEditor
        {
            get
            {
                return this._txtEditor;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtEditor = value;
            }
        }

        protected virtual TextBox txtHelp
        {
            get
            {
                return this._txtHelp;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtHelp = value;
            }
        }

        protected virtual TextBox txtMessage
        {
            get
            {
                return this._txtMessage;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtMessage = value;
            }
        }

        protected virtual TextBox txtTemplName
        {
            get
            {
                return this._txtTemplName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtTemplName = value;
            }
        }

        protected virtual RequiredFieldValidator valReqCategoryName
        {
            get
            {
                return this._valReqCategoryName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._valReqCategoryName = value;
            }
        }
    }
}

